#!/usr/bin python3
# -*- coding: utf-8 -*-
""" sqlalchemy 示例demo"""
from sqlalchemy import Column, String, create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base


# 配置数据库

# 创建对象的基类
Base = declarative_base()

# 数据库表demo
class User(Base):
    """
    sqlalchemy 表映射示例
    """
    __tablename__ = "user"
    id = Column("id", String(255), primary_key=True)
    name = Column("name", String(255))
    account = Column("account", String(255))
    password = Column("password", String(255))
    part = Column("part", String(255))
    company = Column("company", String(255))
    title = Column("title", String(255))


# 实例化数据库引擎
engine = create_engine("postgresql+psycopg2://postgres:12345@120.25.204.182:5432/postgres")

# 创建DBSession类型
DBSession = sessionmaker(bind=engine)


# 启动测试
if __name__ == "__main__":
    session = DBSession()
    user = session.query(User).filter(User.id == "5").one()

    print("name", user.name)
